package logic

import (
	"context"
	"select/models/mysql"

	"select/selectrpc/internal/svc"
	"select/selectrpc/selectrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopShowLogic {
	return &ShopShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopShowLogic) ShopShow(in *selectrpc.ShopShowRequest) (*selectrpc.ShopShowResponse, error) {
	// todo: add your logic here and delete this line

	var shop mysql.ShopClassBrand
	mysql.DB.Debug().Where("id=?", in.Id).Find(&shop)
	mysql.DB.Debug().Table("shops").Where("shops", in.Id).
		Select("shops.*, classes.name as classes_name , brands.name as brands_name").
		Joins("left join classes on class_id = shops.class.id").
		Joins("left join brands on brands_id = shops.brand.id").
		Find(&shop)
	return &selectrpc.ShopShowResponse{
		Name:    shop.Name,
		Price:   float32(shop.Price),
		ClassId: shop.ClassId,
		BrandId: shop.BrandId,
	}, nil
}
